var zixunAjaxUrl = jsCtx+'/shop/frontMyMessageManage.do';  //Ajax的url




onloadlist.push(function(){  //页面加载后，发送第一此请求 ；

	var pid = document.getElementById('pid').value;
	zixunAjax('POST' ,zixunAjaxUrl,'method=myMessageList&pager.offset=0&pageSize=20&myMessage.code='+pid,zixunCallback );
	
});
var zixunAjax = function(type,url,query,callback){
	var xmlhttp=null;
	if(window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
	}
	else if(window.ActiveXObject) {
		xmlhttp=new ActiveXObject("MSXML2.XMLHTTP.3.0");
		if(!xmlhttp){
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		if(!xmlhttp){
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	if(xmlhttp){
		xmlhttp.open(type,((type=="POST") ? url : url+"?"+query),true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){
				if(xmlhttp.status==200){
					callback(xmlhttp.responseXML);
				}
			}
		};
		xmlhttp.send((type=="POST") ? query : null);
	}
};

var zixunCallback = function(doc){
	var contentDiv = document.getElementById('bodyid');    //页面需要刷新的部分，目前是  <div class="description">,需要加id等来处理 ;
	var doc = doc.getElementsByTagName('root')[0];
	/**
用户ID,
会员级别
咨询时间
咨询内容
客服回复
-------
咨询总条数
当前页数
<xml ? ====>
<root>
<allcount>111</allcount>
<currentPage>333/<cu
<contents>
	<ids>id</ids>
	<levels></levels>
	<times>time</times>
	<answers>answer</answers>
	<replys>reply<replys>
</content>
< contents /> .....循环
</root>
**/
var allcount = doc.getElementsByTagName('allcount')[0].firstChild.nodeValue;


var currentPage = doc.getElementsByTagName('currentPage')[0].firstChild.nodeValue;
var allPages = Math.ceil(allcount/20) ;
var contents = doc.getElementsByTagName('contents');
var pid = document.getElementById('pid').value;

var str = '<div class="qa_status" style="float:none;text-align:right;width:720px;">此问答区只针对所属商品的性能和参数，其它问题请在<a href="http://www.rayi.cn/bbs">锐意网社区</a>咨询</div>';
for(var i=0;i<contents.length;i++){
	str += '<div class="qa_all" style="float:none;"><div class="qa_name" style="float:none;height:16px;"><span style="float:left">昵称';
	str += contents[i].getElementsByTagName('ids')[0].firstChild.nodeValue;
	str += '</span><span style="float:right;">发布时间';
	str += contents[i].getElementsByTagName('times')[0].firstChild.nodeValue;
	str += '</span></div><div class="qa_cont" style="float:none;"><div style="text-align:left;line-height:20px;">咨询内容：';
	str+=contents[i].getElementsByTagName('answers')[0].firstChild.nodeValue +'</div><div style="color:#888888;text-align:left;line-height:20px;">客服回复：';
	var replys = "";
	if(contents[i].getElementsByTagName('replys')[0].firstChild != null){
		replys  = contents[i].getElementsByTagName('replys')[0].firstChild.nodeValue;
	} 
	
	str+= replys +'</div></div></div>';
}
str += '<div class="qa_page" style="float:none;"><div style="height:20px;line-height:20px;">此商品咨询问答共 '+allcount+' 条　　';
str += '<a href="#" onclick=\'zixunAjax('+'"POST","'+zixunAjaxUrl +'","method=myMessageList&pager.offset=0&pageSize=20&myMessage.code='+pid+'",zixunCallback'+');return false\'>首页</a>&nbsp;&nbsp;';


if(currentPage >19){
	var pre = currentPage- 20 ; if(pre <0) pre = 0;
	str += '<a href="#" onclick=\'zixunAjax('+'"POST","'+zixunAjaxUrl +'","method=myMessageList&pager.offset='+pre+'&pageSize=20&myMessage.code='+pid+'",zixunCallback'+');return false\'>上页</a>&nbsp;&nbsp;';
}else{
	str += '<a href="#" onclick=\'return false\'>上页</a>&nbsp;&nbsp;';
}
if(currentPage<(allcount-20)){
	var next = currentPage -(-20); if(next >allcount) next = currentPage;
	str += '<a href="#" onclick=\'zixunAjax('+'"POST","'+zixunAjaxUrl +'","method=myMessageList&pager.offset='+next+'&pageSize=20&myMessage.code='+pid+'",zixunCallback'+');return false\'>下页</a>&nbsp;&nbsp;';
}else{
	str += '<a href="#" onclick=\'return false\'>下页</a>&nbsp;&nbsp;';
}
var tail = allcount - allcount%20 ;
str+='<a href="#" onclick=\'zixunAjax('+'"POST","'+zixunAjaxUrl +'","method=myMessageList&pager.offset='+tail+'&pageSize=20&myMessage.code='+pid+'",zixunCallback'+');return false\'>尾页</a>&nbsp;&nbsp;</div>';

str += '<form action="'+jsCtx+'/shop/frontMyMessageManage.do?method=insertMyMessage"  name="zixunForm" method="post" ><div class="qa_info" style="float:none;">添加内容：<br /><label><textarea name="myMessage.content"></textarea></label><br /><input type="hidden" name="myMessage.code" id="myMessageCode" value="'+pid+'"/>';
str += '<a href="javascript:document.zixunForm.submit();document.zixunForm.action=\'#\';"  class="inquiry_manu">提交</a></div></form></div>';

contentDiv.innerHTML = str ;
};

 
















